﻿using System.Web.Mvc;
using WebApplication4.Services;
using Work3.Models;

namespace WebApplication4.Controllers
{
    public class HomeController : Controller
    {
        private loginService _service = new loginService();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Login(UserMsg form)
        {
            if (form.Username == null) {
                Session["alert"] = "账号不能为空";
                return RedirectToAction("Index");
            }

            if (form.Password == null) {
                Session["alert"] = "密码不能为空";
                return RedirectToAction("Index");
            }
            Session["login"] = _service.Login(form);
            if ((int)Session["login"] == 1) {
                Session["user"] = form.Username;
                Session["Status"] = 1;
                ViewBag.Status = 1;
                ViewBag.username = form.Username;
                return RedirectToAction("Index", "admin");
            }
            return RedirectToAction("Index");
        }
    }
}